package com.liming.salesman.webapp.wicket.page;

import com.liming.salesman.api.biz.ISalesmanBeanService;
import com.liming.salesman.api.persistence.ISalesmanBean;
import com.liming.salesman.entities.SalesmanBeanImpl;
import org.apache.aries.blueprint.annotation.Reference;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * @类描述： 添加销售顾问页面对应类
 * @创建人：wkr
 * @创建时间：2014-3-27 下午19:01:59
 * @修改人：wkr
 * @修改时间：2014-3-27 下午19:01:59
 * @修改备注：
 */
public class AddSalesman extends Panel {
    @Named
    @Inject
    @Reference(id = "salesmanBeanService", serviceInterface = ISalesmanBeanService.class)
    private ISalesmanBeanService salesmanBeanService;

    TextField loginName;
    PasswordTextField password;
    TextField name;
    TextField email;
    TextField sex;
    TextField distributor;
    ISalesmanBean user = new SalesmanBeanImpl();

    public AddSalesman(String id) {
        super(id);

        Form form = new Form<ISalesmanBean>("add_user_form", new CompoundPropertyModel<ISalesmanBean>(user)) {
            @Override
            protected void onSubmit() {
                user.setPassword(password.getValue());
                user.setName(name.getValue());
                user.setEmail(name.getValue());
                user.setSex(sex.getValue());
                user.setLoginName(loginName.getValue());
                user.setDistributor(distributor.getValue());
                salesmanBeanService.addSalesman(user);
                setResponsePage(SalesmanPage.class);
            }
        };
        add(form);

        loginName = new TextField("loginName");
        password = new PasswordTextField("password");
        name = new TextField("name");
        email = new TextField("email");
        sex = new TextField("sex");
        distributor = new TextField("distributor");

        form.add(loginName);
        form.add(password);
        form.add(name);
        form.add(email);
        form.add(sex);
        form.add(distributor);
    }
}


